using System;
using System.Linq;
using System.Runtime.Serialization;
using FireStarter.Base;
using Habanero.BO;
using Habanero.Util;

namespace Firestarter.DB.Schema.BO
{

    public class DBViewColumn : BusinessObject, IMergableBo, IDBColumn
    {
              public DBViewColumn(string columnName)
        {
            SetColumnName(columnName);
        }

        protected DBViewColumn(ConstructForFakes constructForFakes) : base(constructForFakes)
        {
        }

        public DBViewColumn()
        {
            
        }

        private void SetColumnName(string columnName)
        {
            this.ColumnName = columnName;
        }

        protected DBViewColumn(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        public override string ToString()
        {
            return ViewName + " - " + this.ColumnName;
        }

        /// <summary>
        /// Whether this change is approved to be applied to the domain model
        /// </summary>
        public bool PendingChangeApproved
        {
            get { return Approved ?? false; }
            set { Approved = value; }
        }

        public string ViewName
        {
            get
            {
                return this.View == null ? "" : this.View.TableName;
            }
        }


        #region Properties
        public virtual Guid? ColumnID
        {
            get
            {
                return ((Guid?)(base.GetPropertyValue("ColumnID")));
            }
            set
            {
                base.SetPropertyValue("ColumnID", value);
            }
        }

        public virtual String ColumnName
        {
            get
            {
                return ((String)(base.GetPropertyValue("ColumnName")));
            }
            set
            {
                base.SetPropertyValue("ColumnName", value);
            }
        }

        public virtual String DataType
        {
            get
            {
                return ((String)(base.GetPropertyValue("DataType")));
            }
            set
            {
                base.SetPropertyValue("DataType", value);
            }
        }

        public virtual Int32? DataLength
        {
            get
            {
                return ((Int32?)(base.GetPropertyValue("DataLength")));
            }
            set
            {
                base.SetPropertyValue("DataLength", value);
            }
        }

        public virtual Boolean? Nullable
        {
            get
            {
                return ((Boolean?)(base.GetPropertyValue("Nullable")));
            }
            set
            {
                base.SetPropertyValue("Nullable", value);
            }
        }

        public virtual String DefaultValue
        {
            get
            {
                return ((String)(base.GetPropertyValue("DefaultValue")));
            }
            set
            {
                base.SetPropertyValue("DefaultValue", value);
            }
        }

        public virtual Guid? TableID
        {
            get
            {
                return ((Guid?)(base.GetPropertyValue("ViewID")));
            }
            set
            {
                base.SetPropertyValue("ViewID", value);
            }
        }

        public virtual Boolean? IsAutoIncrementing
        {
            get
            {
                return ((Boolean?)(base.GetPropertyValue("IsAutoIncrementing")));
            }
            set
            {
                base.SetPropertyValue("IsAutoIncrementing", value);
            }
        }

        public virtual String Comment
        {
            get
            {
                return ((String)(base.GetPropertyValue("Comment")));
            }
            set
            {
                base.SetPropertyValue("Comment", value);
            }
        }

        public virtual Int32? OrdinalPosition
        {
            get
            {
                return ((Int32?)(base.GetPropertyValue("OrdinalPosition")));
            }
            set
            {
                base.SetPropertyValue("OrdinalPosition", value);
            }
        }

        public IDBTable DBTable
        {
            get { return this.View; }
        }

        public virtual ChangeType PendingChangeType
        {
            get
            {
                return ((ChangeType)(base.GetPropertyValue("PendingChangeType")));
            }
            set
            {
                base.SetPropertyValue("PendingChangeType", value);
            }
        }

        public virtual Boolean? Approved
        {
            get
            {
                return ((Boolean?)(base.GetPropertyValue("Approved")));
            }
            set
            {
                base.SetPropertyValue("Approved", value);
            }
        }
        #endregion

        #region Relationships


        public virtual DBView View
        {
            get
            {
                return Relationships.GetRelatedObject<DBView>("View");
            }
            set
            {
                Relationships.SetRelatedObject("View", value);
            }
        }
        #endregion
    }
}